package com.hrhx.springboot;

import java.util.List;

public class TimeCostCalculator  
{  
   public TimeCostCalculator()  
   {  
   }  
  
   /** 
    * 计算指定对象的运行时间开销。 
    *  
    * @param testCase 指定被测对象。 
    * @return 返回sub.run的时间开销，单位为s。 
    * @throws Exception 
    */  
   public double calcTimeCost(TestCase testCase) throws Exception  
   {  
      List<Object> params = testCase.getParams();  
      long startTime = System.nanoTime();  
      Object result = testCase.run(params);  
      long stopTime = System.nanoTime();  
      testCase.printResult(result);  
      System.out.println("start: " + startTime + " / stop: " + stopTime);  
      double timeCost = (stopTime - startTime) * 1.0e-9;  
      return timeCost;  
   }  
  
   public static void main(String[] args) throws Exception  
   {  
      TimeCostCalculator tcc = new TimeCostCalculator();  
      double timeCost;  
  
      System.out.println("--------------------------------------------------------------------------");  
      timeCost = tcc.calcTimeCost(new CalcCurveFitting());  
      System.out.println("time cost is: " + timeCost + "s");  
      System.out.println("--------------------------------------------------------------------------");  
   }  
}